import { UserEntity, UserIdentityEntity, UserInfoEntity, UserVo } from "@/biz/interface/userType";
import http from "@/api";
import { ModuleUmsUrl } from "..";
import { ResPage } from "@/api/interface";

const moduleUrl = ModuleUmsUrl;

export type ResUserList = {
  id: string;
  name: string;
  gender: string;
  age: number;
  idCard: string;
  email: string;
  address: string;
  createTime: string;
  flagActive: string;
  status: number;
  avatar: string;
};

// * 获取部门的用户列表
export const getDeptUserListApi = (params: { deptId: string }) => {
  return http.post<ResPage<UserVo>>(moduleUrl + `/sys/deptusers`, params);
};

// * 获取用户列表
export const getUserListApi = (params: any) => {
  return http.post<ResPage<UserVo>>(moduleUrl + `/sys/sysusers`, params);
};

// * 获取角色下的用户列表
export const addRoleUsersApi = (params: { roleId: string; userIds: string[] }) => {
  return http.post(moduleUrl + `/sys/saveroleusers`, params);
};

// * 获取角色下的用户列表
export const getUsersByRoleApi = (params: { roleId: string }) => {
  return http.post<ResPage<UserVo>>(moduleUrl + `/sys/roleusers`, params);
};

// * 新增用户
export const saveUserApi = (user: UserEntity) => {
  return http.post(moduleUrl + `/sys/savesysuser`, user);
};

// * 获取单个用户详情信息
export const getUserInfoApi = (params: { id: string }) => {
  return http.post<UserEntity>(moduleUrl + `/sys/userinfo`, params);
};

// * 获取当前登录用户详情信息
export const getCurUserInfoApi = (params: {}) => {
  return http.post<UserInfoEntity>(moduleUrl + `/sys/uservoinfo`, params);
};
// * 保存当前登录用户详情信息
export const saveUserInfoApi = (user: UserInfoEntity) => {
  return http.post(moduleUrl + `/sys/uservosave`, user);
};

// * 删除用户
export const deleteUserApi = (params: { id: string }) => {
  return http.post(moduleUrl + `/sys/userdelete`, params);
};

// * 删除一堆用户
export const deleteUsersApi = (params: { userIds: string[] }) => {
  return http.post(moduleUrl + `/sys/usersdelete`, params);
};

// * 重置用户密码
export const resetUserPasswordApi = (params: { id: string }) => {
  return http.post(moduleUrl + `/sys/userresetpwd`, params);
};

// * 解除用户锁定
export const unlockUserApi = (params: { id: string }) => {
  return http.post(moduleUrl + `/sys/unlock`, params);
};

// * 修改用户密码 - 只有当前登录用户才能调用这个接口
export const changeUserPasswordApi = (params: { npassword: string }) => {
  return http.post(moduleUrl + `/sys/userpwd`, params);
};

// * 修改用户的状态
export const changeUserActiveApi = (params: { id: string }) => {
  return http.post(moduleUrl + `/sys/userable`, params);
};

// * 获取单个用户认证信息
export const getUserIdentityApi = (params: { workerId: string }) => {
  return http.post<UserIdentityEntity>(moduleUrl + `/sys/useridentityinfo`, params);
};

// * 获取单个用户认证信息
export const getUserIdentityByCompanyAdminApi = (params: { companyId: string }) => {
  return http.post<UserIdentityEntity>(moduleUrl + `/sys/useridentityinfo`, params);
};

// * 上传用户认证信息
export const handleUserIdentityApi = (params: {}) => {
  return http.post(moduleUrl + `/sys/useridentity`, params);
};

export const handleUserIdentityPassApi = (params: { id: string }) => {
  return http.post<UserIdentityEntity>(moduleUrl + `/cpy/useridp`, params);
};

export const handleUserIdentityRefuseApi = (params: { id: string }) => {
  return http.post<UserIdentityEntity>(moduleUrl + `/cpy/useridf`, params);
};

// * 解决用户和企业的绑定关系
export const unbindByCompanyApi = (params: { id: string }) => {
  return http.post(moduleUrl + `/cpy/unbindbycpy`, params);
};
